package com.wisdom.benefit.jufa.product;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.wisdom.benefit.jufa.event.CallBackOtherInterface;
import com.wisdom.benefit.jufa.R;

import java.util.ArrayList;

public class AccountSettingAdapter extends BaseAdapter {
    private ArrayList<AccountSettingBean> datas;
    private Context context;
    private CallBackOtherInterface callback; //回调接口


    public AccountSettingAdapter(ArrayList<AccountSettingBean> datas, Context context, CallBackOtherInterface callback) {
        this.datas = datas;
        this.context = context;
        this.callback = callback;
    }


    @Override
    public int getCount() {
        return datas.size();
    }


    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AccountSettingAdapter.ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.account_setting_item, parent, false);
            holder = new AccountSettingAdapter.ViewHolder();
            holder.nameTv = (TextView) convertView.findViewById(R.id.account_setting_tv);
            holder.btn = (Button) convertView.findViewById(R.id.account_setting_item_btn);
            holder.isDoTv = convertView.findViewById(R.id.account_setting_isdo_tv);
            holder.deleteBtn = (Button) convertView.findViewById(R.id.account_setting_item_delete_btn);
            holder.imageView = (ImageView) convertView.findViewById(R.id.account_setting_item_ivlook);
            convertView.setTag(holder);
        } else {
            holder = (AccountSettingAdapter.ViewHolder) convertView.getTag();
        }
        holder.nameTv.setText(datas.get(position).getPayeeName());
        if (datas.get(position).getReceivingAccount() == 0) {
            holder.btn.setText("开启");
            holder.isDoTv.setText("已关闭");
        } else {
            holder.btn.setText("关闭");
            holder.isDoTv.setText("已开启");
        }
        holder.btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callback.callBackClick(position);
            }
        });
        holder.btn.setTag(position);
        holder.deleteBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callback.callBackClickOther(position);
            }
        });
        holder.deleteBtn.setTag(position);

        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callback.callIvBackClick(position);
            }
        });
        holder.imageView.setTag(position);
        return convertView;
    }

    static class ViewHolder {
        TextView nameTv,isDoTv;
        Button btn, deleteBtn;
        ImageView imageView;
    }

}


